package com.models;

import com.dao.TableDao;
import com.dao.impl.TableDaoImpl;
import com.util.Constants;
import org.junit.Test;

import java.io.*;
import java.util.ArrayList;

/**
 * Created by timeliar on 15-9-29.
 *
 */
public class TableDataTest {
    private TableDao tableDao;
    public TableDataTest(){
        tableDao = new TableDaoImpl();
    }
    @Test
    public void testArray(){
        TableData tableData = new TableData(tableDao.getTable("aa"));
        try {
            for(int i = 0 ; i < 100 ; i++){
                tableData.insertRow(new ArrayList<>());
            }
            try {
                ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(Constants.TABLE_DATA+"/aa.dat"));
                outputStream.writeObject(tableData);
                outputStream.flush();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (com.util.Error error) {
            error.printStackTrace();
        }
    }

    @Test
    public void testGetData() throws Exception {
        ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(Constants.TABLE_DATA+"/aa.dat"));
        TableData data =  (TableData)inputStream.readObject();
        System.out.println(data.getColCount());
    }

}